package com.sjq.common.service.impl;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import com.sjq.common.dao.OperationLogDao;
import com.sjq.common.entity.OperationLog;
import com.sjq.common.entity.Result;
import com.sjq.common.service.OperationLogService;
import com.sjq.common.util.Page;

@Service
public class OperationLogServiceImpl implements OperationLogService{
	@Resource
	private OperationLogDao czrzDao;

	@Override
	public Result<OperationLog> save(OperationLog czrz) {
		Result<OperationLog> result=new Result<OperationLog>();
		int count=czrzDao.save(czrz);
		if(count>0){
			result.setMsg("操作日志新增成功");
			result.setStatus(0);
		}else{
			result.setMsg("操作日志新增失败");
			result.setStatus(1);
		}
		return result;
	}
	
	@Override
	public String selectPage(String pages,String czlxdm,String cazr_xm,String cazr_gmsfhm,String cazr_ipdz) {
		OperationLog ol = new OperationLog();
		ol.setCzlxdm(czlxdm);
		ol.setCazr_xm(cazr_xm);
		ol.setCazr_gmsfhm(cazr_gmsfhm);
		ol.setCazr_ipdz(cazr_ipdz);
		List<OperationLog> list = czrzDao.queryByCzrz(ol);
		int count = list.size();
		int pageNum = Integer.parseInt(pages);
		Page page = new Page(pageNum, count);
		/*page.setPageSize(2);*/
		List<OperationLog> datas = czrzDao.queryByPaging(ol, page.getStart(),  page.getEnd());
		Map map = new HashMap();
		map.put("page", page);
		map.put("datas", datas);
		String json=JSONObject.fromObject(map).toString();
		return json;
	}
	
}
